﻿/**
 * @file MainForm
 *
 * @brief 
 *
 * @author gyzheng
 *
 * @mail gyazheng@gmail.com
 *
 * @date 07/27/2011 22:37:51 
 *
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using CarFrameWork.Model;
using CarFrameWork.Common;
using CarFrameWork.Controller;

using CarFrameWork.UI;
using CarFrameWork.UI.Common;
using CarFrameWork.UI.SystemManage;
using CarFrameWork.UI.SystemManage.RoleManage;
using CarFrameWork.UI.SystemManage.UserManage;
using CarFrameWork.UI.SystemManage.ModelManage;
using CarFrameWork.UI.SystemManage.ParameManage;
using CarFrameWork.UI.SystemManage.GroupMangage;

using CarFrameWork.UI.InfoManage.Mangage;
using CarFrameWork.UI.InfoManage.TaskManage;

using CarFrameWork.UI.PerformanceQuery;

using CarFrameWork.UI.ProductDesign.PartExamine.HouQiao;
using CarFrameWork.UI.ProductDesign.PartExamine.FenDongQi;

using CarFrameWork.UI.ProductDesign.PartsCAEAnalysis;
using CarFrameWork.UI.ProductDesign._3DModelingDesign;
using CarFrameWork.UI.ProductDesign._3DModelingAssembly;

using CarFrameWork.UI.ProductDesign.VehicleMatch;

using CarFrameWork.UI.Other;


namespace CarFrameWork
{
    public partial class MainForm : Form
    {
        //MainInfoForm mainInfo;
        private bool isMsgClose = false;
        private string skinFolder = string.Empty;
        Form ChildForm;

        #region Signle Contract
        private static MainForm m_Current;

        public static MainForm Current
        {
            get 
            {
                if (m_Current == null)
                {
                    m_Current = new MainForm();
                }
                return m_Current;
            }
        }

        private MainForm()
        {
            Global.skinFolder = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\Styles\\Vista.cjstyles";
            skinFramework = new AxXtremeSkinFramework.AxSkinFramework();
            ((System.ComponentModel.ISupportInitialize)(skinFramework)).BeginInit();
            this.Controls.Add(skinFramework);
            ((System.ComponentModel.ISupportInitialize)(skinFramework)).EndInit();
            skinFramework.LoadSkin(Global.skinFolder, "Normalblue.ini");

            InitializeComponent();
            //this.ClientSize.Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            //this.ClientSize.Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            this.ClientSize = new System.Drawing.Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

        }
        /// <summary>
        /// skin在加载时
        /// </summary>
        /// <param name="e"></param>
        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);
            if (this.Visible)
            {
                skinFramework.ApplyWindow(this.Handle.ToInt32());
                this.BackColor = skinFramework.GetColor(XtremeSkinFramework.XTPColorManagerColor.STDCOLOR_BTNFACE);
            }
        }

        /// <summary>
        /// skin在结束时
        /// </summary>
        /// <param name="e"></param>
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
        }
        #endregion

        private void MainForm_Load(object sender, EventArgs e)
        {
            InitMenu();
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            Global.Screen_Height = this.panelMain.Height;
            Global.Screen_Width = this.panelMain.Width;
            //MainInfoForm mainInfo = new MainInfoForm();
            //ShowChildrenForm(mainInfo); 
            toolStripStatusLabel2.Text = "当前用户：" + Global.User_Name;
            toolStripStatusLabel3.Text = "隶属组："+Global.User_Group;
        }

        private void InitMenu()
        {
            //menuItem.Items[1].Enabled = false;
            OperationMenu menu = new OperationMenu(menuItem,Global.User_Permissions);
            menu.InitMenu();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (isMsgClose)
            {
                e.Cancel = false;
                return;
            }
            if (MsgHelper.ShowQuestionMsgBox("确定要关闭系统吗？") == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }
        }

        private void MainForm_MdiChildActivate(object sender, EventArgs e)
        {
            this.menuItem.SuspendLayout();
            this.menuItem.ResumeLayout();
        }

        private void ShowChildrenForm(Form childrenForm)
        {
            //ChildrenForm = childrenForm;
            //childrenForm.MdiParent = this;
            //if (this.ActiveMdiChild != null)
            //    this.ActiveMdiChild.Close();
            //childrenForm.Activate();
            //childrenForm.WindowState = FormWindowState.Maximized;
            ////childrenForm.WindowState = FormWindowState.Normal;
            ////childrenForm.Dock = DockStyle.Fill;
            //childrenForm.Show();
            //childrenForm.Refresh();
            ////childrenForm.ShowDialog();

            ChildForm = childrenForm;
            childrenForm.TopLevel = false;
            panelMain.Controls.Clear();
            panelMain.Controls.Add(childrenForm);
            childrenForm.Dock = System.Windows.Forms.DockStyle.Fill;
            childrenForm.FormBorderStyle = FormBorderStyle.None;
            //childrenForm.WindowState = FormWindowState.Maximized;
            childrenForm.Height = this.panelMain.Height;
            childrenForm.Width = this.panelMain.Width;
            childrenForm.Show();
        }

        private void 用户管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UserMainForm userInfo = new UserMainForm();
            ShowChildrenForm(userInfo);
        }

        private void 权限管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RoleMainForm roleInfo = new RoleMainForm();
            ShowChildrenForm(roleInfo);
        }

        private void 模块管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ModelMainForm modelInfo = new ModelMainForm();
            ShowChildrenForm(modelInfo);
        }

        private void 参数设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ParameMainForm parameInfo = new ParameMainForm();
            ShowChildrenForm(parameInfo);
        }

        private void 群组管理toolStripMenuItem_Click(object sender, EventArgs e)
        {
            GroupMainForm groupInfo = new GroupMainForm();
            ShowChildrenForm(groupInfo);
        }

        private void 通知发布与管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewMainForm newInfo = new NewMainForm();
            ShowChildrenForm(newInfo);
        }

        private void 任务发布及管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TaskMainForm taskInfo = new TaskMainForm();
            ShowChildrenForm(taskInfo);
        }

        private void 切换用户ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoginForm loginForm = new LoginForm();
            MainForm.m_Current = null;
            this.isMsgClose = true;
            this.Hide();
            this.Close();
            loginForm.ShowDialog();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void 产品性能查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QueryMainForm queryInfo = new QueryMainForm();
            ShowChildrenForm(queryInfo);
        }

        private void 任务进度查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TaskProgressForm taskInfo = new TaskProgressForm();
            ShowChildrenForm(taskInfo);
        }

        private void 主界面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MainInfoForm mainInfo = new MainInfoForm();
            ShowChildrenForm(mainInfo);
        }

        private void 整车匹配性能计算ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            VehicleMatchExamineMainForm vmemf = new VehicleMatchExamineMainForm();
            ShowChildrenForm(vmemf);
        }

        private void 部件性能校核ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CarFrameWork.UI.ProductDesign.PartExamine.AccessControlForm accessControl = new CarFrameWork.UI.ProductDesign.PartExamine.AccessControlForm();
            ShowChildrenForm(accessControl);
        }

        private void 部件CAE分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CarFrameWork.UI.ProductDesign.PartsCAEAnalysis.AccessControlForm accessControl = new CarFrameWork.UI.ProductDesign.PartsCAEAnalysis.AccessControlForm();
            ShowChildrenForm(accessControl);
        }

        private void 三维数模自动化设计ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CarFrameWork.UI.ProductDesign._3DModelingDesign.AccessControlForm accessControl = new CarFrameWork.UI.ProductDesign._3DModelingDesign.AccessControlForm();
            ShowChildrenForm(accessControl);
        }

        private void 三维模型自动化装配ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CarFrameWork.UI.ProductDesign._3DModelingAssembly.AccessControlForm accessControl = new CarFrameWork.UI.ProductDesign._3DModelingAssembly.AccessControlForm();
            ShowChildrenForm(accessControl);
        }

        private void 产品ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DocumentManagementForm dmForm = new DocumentManagementForm();
            ShowChildrenForm(dmForm);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "当前时间："+DateTime.Now.ToString();
        }

        private void 帮助ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            HelpFrm helpForm = new HelpFrm();
            ShowChildrenForm(helpForm);
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutFrm about = new AboutFrm();
            about.ShowDialog();
        }

        private void MainForm_Resize(object sender, EventArgs e)
        {
            //this.ChildForm.Refresh();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            MainInfoForm mainInfo = new MainInfoForm();
            ShowChildrenForm(mainInfo); 
            this.timer2.Enabled = false;
        }

        private void menuItem_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
    }
}
